package com.binhai.springboot.project.service;


import com.binhai.springboot.project.bean.ProjectBean;
import com.binhai.springboot.project.dao.ProjectBeanDao;
import com.binhai.springboot.user.bean.UserBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ProjectService {


    @Autowired
    private ProjectBeanDao beanDao;

    @Autowired
    private HttpSession session;


    public List getAllData() {

        return beanDao.getAllData();
    }

    public List selectData(String name) {

        return beanDao.selectData(name);

    }

    public Map saveData(ProjectBean bean) {
        Map re = new HashMap ( );
        try {
            beanDao.insertReturnId(bean);
            beanDao.insertOrgids(bean);
            re.put ("result", "success");
        } catch (Exception e) {
            re.put ("result", "error");
            e.printStackTrace ( );
        }
        return re;
    }


    public Map updateData(ProjectBean bean) {
        Map re = new HashMap();
        try {
            //修改数据
            beanDao.updateByPrimaryKeySelective(bean);
            //删除关联的部门信息
            beanDao.deleteOrgids(bean);
            //批量保存关联的部门信息
            beanDao.insertOrgids(bean);
            //批量保存关联的角色信息


            re.put("result", "success");
        } catch (Exception e) {
            re.put("result", "error");
            e.printStackTrace();
        }
        return re;
    }

    public Map deleteData(ProjectBean bean) {
        Map re = new HashMap();
        try {

            beanDao.deleteData(bean);
            beanDao.deleteOrgids(bean);
            re.put("result", "success");
        } catch (Exception e) {
            re.put("result", "error");
            e.printStackTrace();
        }
        return re;
    }

    public Map deleteDatas(int[] ids) {
        Map re = new HashMap();
        try {
            //批量删除用户数据
            beanDao.deleteDatas (ids);
            //批量删除关联的部门信息
            beanDao.deleteOrgidsForBath(ids);
            re.put("result", "success");
        } catch (Exception e) {
            re.put("result", "error");
            e.printStackTrace();
        }
        return re;
    }

}